<!-- Modal -->
<div class="modal fade " id="addContactModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 60%">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">机构通讯录</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">机构名称</label>
                        <div class="col-sm-8">
                            <input id="addContactModal_contactId" type="hidden">
                            <input id="addContactModal_institutionName" type="text" class="form-control"
                                   style="width: 50%;" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span style="color:red"></span>联系人姓名</label>
                        <div class="col-sm-3">
                            <input id="addContactModal_name" type="text" class="form-control">
                        </div>
                        <label class="col-sm-2 control-label">联系人职位</label>
                        <div class="col-sm-3">
                            <input id="addContactModal_position" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">联系人手机号码</label>
                        <div class="col-sm-3">
                            <input id="addContactModal_mobPhone" type="text" class="form-control">
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">联系人座机号码</label>
                        <div class="col-sm-3">
                            <input id="addContactModal_telPhone" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">联系人邮箱</label>
                        <div class="col-sm-3">
                            <input id="addContactModal_email" type="text" class="form-control"/>
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">是否有效</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width: 100%;" id="addContactModal_status">
                                <option value="1">有</option>
                                <option value="0">无</option>
                            </select>
                        </div>
                    </div>

                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                                onclick="addContactModal_save()">保存
                        </button>
                    </div>
                    <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>

<script>

    function addContactModal_init() {
        $("#addContactModal_contactId").val("");
        $("#addContactModal_institutionName").val("");
        $("#addContactModal_name").val("");
        $("#addContactModal_position").val("");
        $("#addContactModal_mobPhone").val("");
        $("#addContactModal_telPhone").val("");
        $("#addContactModal_email").val("");
        $("#addContactModal_status").val("");
    }

    function addContactModal_setValue(inde) {
        var table1Row = $("#table1").bootstrapTable("getSelections")[0];
        $("#addContactModal_institutionName").val(table1Row.shortName);
        if (inde != -1) {
            var options = $("#table2").bootstrapTable("getData");
            var row = options[inde];
            $("#addContactModal_contactId").val(row.id);
            $("#addContactModal_name").val(row.name);
            $("#addContactModal_position").val(row.position);
            $("#addContactModal_mobPhone").val(row.mobPhone);
            $("#addContactModal_telPhone").val(row.telPhone);
            $("#addContactModal_email").val(row.email);
            $("#addContactModal_status").select2("val", row.status);
        }
    }


    function addContactModal_save() {
        var name = $("#addContactModal_name").val();
        if (name == "" || undefined == name) {
            toastr['error']('请输入联系人名称', '提示');
            return;
        }
        var data = {
            id: $("#addContactModal_contactId").val(),
            name: $("#addContactModal_name").val(),
            position: $("#addContactModal_position").val(),
            mobPhone: $("#addContactModal_mobPhone").val(),
            telPhone: $("#addContactModal_telPhone").val(),
            email: $("#addContactModal_email").val(),
            status: $("#addContactModal_status").val(),
            institutionId: $("#table1").bootstrapTable("getSelections")[0].id
        };
        var url = "/institutioncontact/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table2").bootstrapTable("refresh");
                $("#addContactModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
